<!DOCTYPE html>
<html lang=zh>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="SpringBoot项目1.区分线上线下环境配置maven项目：在pom.xml文件中的dependencies标签前添加如下代码 1234567891011121314151617181920 &lt;profiles&gt;    &lt;!--除了dev、pro还可以再添加多个配置--&gt;    &lt;profile&gt;        &lt;id&gt;dev&lt;&#x2F;id&amp;gt">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring项目logback配置多环境日志输出">
<meta property="og:url" content="https:&#x2F;&#x2F;fengzxia.gitee.io&#x2F;posts&#x2F;5f5c7dc7.html">
<meta property="og:site_name" content="只是学习学习的博客">
<meta property="og:description" content="SpringBoot项目1.区分线上线下环境配置maven项目：在pom.xml文件中的dependencies标签前添加如下代码 1234567891011121314151617181920 &lt;profiles&gt;    &lt;!--除了dev、pro还可以再添加多个配置--&gt;    &lt;profile&gt;        &lt;id&gt;dev&lt;&#x2F;id&amp;gt">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-03-23T06:29:26.000Z">
<meta property="article:modified_time" content="2020-04-16T12:11:08.676Z">
<meta property="article:author" content="只是学习学习">
<meta property="article:tag" content="区分项目环境">
<meta name="twitter:card" content="summary">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>Spring项目logback配置多环境日志输出</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
    
<meta name="generator" content="Hexo 4.1.1"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/posts/56379dd4.html"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/posts/5b6de3c3.html"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://fengzxia.gitee.io/posts/5f5c7dc7.html" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&text=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&is_video=false&description=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=Spring项目logback配置多环境日志输出&body=Check out this article: https://fengzxia.gitee.io/posts/5f5c7dc7.html"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&name=Spring项目logback配置多环境日志输出&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=https://fengzxia.gitee.io/posts/5f5c7dc7.html&t=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot项目"><span class="toc-number">1.</span> <span class="toc-text">SpringBoot项目</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-区分线上线下环境配置"><span class="toc-number">1.1.</span> <span class="toc-text">1.区分线上线下环境配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-在logback中通过如下方式进行区分环境"><span class="toc-number">1.2.</span> <span class="toc-text">2.在logback中通过如下方式进行区分环境</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringMVC项目"><span class="toc-number">2.</span> <span class="toc-text">SpringMVC项目</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-区分线上线下环境配置-1"><span class="toc-number">2.1.</span> <span class="toc-text">1.区分线上线下环境配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-在pom文件中引入maven-war-plugin插件，这样作是为了在编译时，web-xml文件能识别-profileActive"><span class="toc-number">2.2.</span> <span class="toc-text">2.在pom文件中引入maven-war-plugin插件，这样作是为了在编译时，web.xml文件能识别${profileActive}</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-在web-xml文件中修改spring-profiles-default配置，没有则添加"><span class="toc-number">2.3.</span> <span class="toc-text">3.在web.xml文件中修改spring.profiles.default配置，没有则添加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-创建一个监听器，继承ContextLoaderListener"><span class="toc-number">2.4.</span> <span class="toc-text">4.创建一个监听器，继承ContextLoaderListener</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-引入logback使用if判断需要的依赖"><span class="toc-number">2.5.</span> <span class="toc-text">5.引入logback使用if判断需要的依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-在logback中使用if判断区分环境"><span class="toc-number">2.6.</span> <span class="toc-text">6.在logback中使用if判断区分环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置后没有生效的原因"><span class="toc-number">2.7.</span> <span class="toc-text">配置后没有生效的原因</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#如果SpringMVC按照上述配置无法成功解决办法"><span class="toc-number">3.</span> <span class="toc-text">如果SpringMVC按照上述配置无法成功解决办法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-引入logback与spring整合的依赖设置后可以自定义logback-xml的文件名-路径"><span class="toc-number">3.1.</span> <span class="toc-text">1.引入logback与spring整合的依赖设置后可以自定义logback.xml的文件名&#x2F;路径</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-将logback-xml文件的名字修改，比如叫logback-aaa-xml"><span class="toc-number">3.2.</span> <span class="toc-text">2.将logback.xml文件的名字修改，比如叫logback-aaa.xml</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-在web-xml中配置logback配置文件初始化（注：要写在spring配置的上边）"><span class="toc-number">3.3.</span> <span class="toc-text">3.在web.xml中配置logback配置文件初始化（注：要写在spring配置的上边）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器"><span class="toc-number">3.4.</span> <span class="toc-text">4.将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器</span></a></li></ol></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        Spring项目logback配置多环境日志输出
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">只是学习学习的博客</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2019-03-23T06:29:26.000Z" itemprop="datePublished">2019-03-23</time>
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/Java/">Java</a> › <a class="category-link" href="/categories/Java/Spring/">Spring</a> › <a class="category-link" href="/categories/Java/Spring/SpringBoot/">SpringBoot</a> › <a class="category-link" href="/categories/Java/Spring/SpringMVC/">SpringMVC</a> › <a class="category-link" href="/categories/Java/logback/">logback</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/%E5%8C%BA%E5%88%86%E9%A1%B9%E7%9B%AE%E7%8E%AF%E5%A2%83/" rel="tag">区分项目环境</a>
    </div>


    </div>
  </header>
  

  <div class="content"itemprop ="articleBody">
    <h2 id="SpringBoot项目"><a href="#SpringBoot项目" class="headerlink" title="SpringBoot项目"></a>SpringBoot项目</h2><h3 id="1-区分线上线下环境配置"><a href="#1-区分线上线下环境配置" class="headerlink" title="1.区分线上线下环境配置"></a>1.区分线上线下环境配置</h3><p>maven项目：在pom.xml文件中的dependencies标签前添加如下代码<br> <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">profiles</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--除了dev、pro还可以再添加多个配置--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">profile</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span>&gt;</span>dev<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--设置默认为dev环境--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">activation</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">activeByDefault</span>&gt;</span>true<span class="tag">&lt;/<span class="name">activeByDefault</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">activation</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--标签中的值根据自己的项目环境名去添加，标签名可以自定义，能写多个--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">profileActive</span>&gt;</span>dev<span class="tag">&lt;/<span class="name">profileActive</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">profile</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">profile</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">id</span>&gt;</span>pro<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">profileActive</span>&gt;</span>prod<span class="tag">&lt;/<span class="name">profileActive</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">profile</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">profiles</span>&gt;</span></span><br></pre></td></tr></table></figure><br> pom文件配置后可以在application配置文件中通过@profileActive@方式拿到profileActive的值<br> <figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"> #区分springboot是线上还是线下环境</span></span><br><span class="line"><span class="meta">spring.profiles.active</span>=<span class="string">@profileActive@</span></span><br></pre></td></tr></table></figure></p>
<h3 id="2-在logback中通过如下方式进行区分环境"><a href="#2-在logback中通过如下方式进行区分环境" class="headerlink" title="2.在logback中通过如下方式进行区分环境"></a>2.在logback中通过如下方式进行区分环境</h3><p> 可以根据不同的环境设置不同的日志输出路径<br> <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">springProfile</span> <span class="attr">name</span>=<span class="string">"prod"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"LOG_HOME"</span> <span class="attr">value</span>=<span class="string">"/opt/myapp/logs/mengmeng-admin"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">springProfile</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">springProfile</span> <span class="attr">name</span>=<span class="string">"dev"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"LOG_HOME"</span> <span class="attr">value</span>=<span class="string">"/opt/myapp/logs/mengmeng-admin-dev"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">springProfile</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>如果参照这个配置后启动报 <code>Logback configuration error detected:</code> 错误<br>请参考这篇博客解决 <a href="https://blog.csdn.net/qq_33430083/article/details/91360771" target="_blank" rel="noopener">https://blog.csdn.net/qq_33430083/article/details/91360771</a></p>
</blockquote>
<h2 id="SpringMVC项目"><a href="#SpringMVC项目" class="headerlink" title="SpringMVC项目"></a>SpringMVC项目</h2><h3 id="1-区分线上线下环境配置-1"><a href="#1-区分线上线下环境配置-1" class="headerlink" title="1.区分线上线下环境配置"></a>1.区分线上线下环境配置</h3><p> 同springboot一样<br> <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">profiles</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--除了dev、pro还可以再添加多个配置--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">profile</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span>&gt;</span>dev<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--设置默认为dev环境--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">activation</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">activeByDefault</span>&gt;</span>true<span class="tag">&lt;/<span class="name">activeByDefault</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">activation</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--标签中的值根据自己的项目环境名去添加，标签名可以自定义，能写多个--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">profileActive</span>&gt;</span>devlopment<span class="tag">&lt;/<span class="name">profileActive</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">profile</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">profile</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">id</span>&gt;</span>pro<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">profileActive</span>&gt;</span>production<span class="tag">&lt;/<span class="name">profileActive</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">profile</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">profiles</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<h3 id="2-在pom文件中引入maven-war-plugin插件，这样作是为了在编译时，web-xml文件能识别-profileActive"><a href="#2-在pom文件中引入maven-war-plugin插件，这样作是为了在编译时，web-xml文件能识别-profileActive" class="headerlink" title="2.在pom文件中引入maven-war-plugin插件，这样作是为了在编译时，web.xml文件能识别${profileActive}"></a>2.在pom文件中引入<code>maven-war-plugin</code>插件，这样作是为了在编译时，web.xml文件能识别${profileActive}</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-war-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.1.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">webResources</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">resource</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">directory</span>&gt;</span>src/main/webapp<span class="tag">&lt;/<span class="name">directory</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">filtering</span>&gt;</span>true<span class="tag">&lt;/<span class="name">filtering</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">resource</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">webResources</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="3-在web-xml文件中修改spring-profiles-default配置，没有则添加"><a href="#3-在web-xml文件中修改spring-profiles-default配置，没有则添加" class="headerlink" title="3.在web.xml文件中修改spring.profiles.default配置，没有则添加"></a>3.在web.xml文件中修改spring.profiles.default配置，没有则添加</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">context-param</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">param-name</span>&gt;</span>spring.profiles.default<span class="tag">&lt;/<span class="name">param-name</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- profileActive就是在pom配置的参数名 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">param-value</span>&gt;</span>$&#123;profileActive&#125;<span class="tag">&lt;/<span class="name">param-value</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">context-param</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="4-创建一个监听器，继承ContextLoaderListener"><a href="#4-创建一个监听器，继承ContextLoaderListener" class="headerlink" title="4.创建一个监听器，继承ContextLoaderListener"></a>4.创建一个监听器，继承ContextLoaderListener</h3><p>通过监听器获取到web.xml中<code>spring.profiles.default</code>的值，存入系统属性中</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取项目开发环境监听器</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> 段誉</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@create</span> 2018-09-19 16:56</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">XyyContextLoaderListener</span> <span class="keyword">extends</span> <span class="title">ContextLoaderListener</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Override</span></span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">contextInitialized</span><span class="params">(ServletContextEvent event)</span> </span>&#123;</span><br><span class="line">    String attribute = event.getServletContext().getInitParameter(<span class="string">"spring.profiles.default"</span>);</span><br><span class="line">    System.setProperty(<span class="string">"DEV_MODEL"</span>, attribute);</span><br><span class="line">    <span class="keyword">super</span>.contextInitialized(event);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在web.xml中添加监听器配置，在配置spring.profiles.default标签的后边添加</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">listener</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">listener-class</span>&gt;</span>com.weijian.xiaoyingying.listener.XyyContextLoaderListener<span class="tag">&lt;/<span class="name">listener-class</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">listener</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="5-引入logback使用if判断需要的依赖"><a href="#5-引入logback使用if判断需要的依赖" class="headerlink" title="5.引入logback使用if判断需要的依赖"></a>5.引入logback使用if判断需要的依赖</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.codehaus.janino<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>janino<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.0.6<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- https://mvnrepository.com/artifact/org.codehaus.janino/commons-compiler --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.codehaus.janino<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>commons-compiler<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.0.8<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="6-在logback中使用if判断区分环境"><a href="#6-在logback中使用if判断区分环境" class="headerlink" title="6.在logback中使用if判断区分环境"></a>6.在logback中使用if判断区分环境</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">if</span> <span class="attr">condition</span>=<span class="string">'property("DEV_MODEL").contains("production")'</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">then</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"LOG_HOME"</span> <span class="attr">value</span>=<span class="string">"/opt/myapp/logs/mjsadmin-pro"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">then</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">else</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"LOG_HOME"</span> <span class="attr">value</span>=<span class="string">"/opt/myapp/logs/mjsadmin-dev"</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">else</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="配置后没有生效的原因"><a href="#配置后没有生效的原因" class="headerlink" title="配置后没有生效的原因"></a>配置后没有生效的原因</h3><ul>
<li><strong>有些项目可能因为配置的原因导致logback初始化执行在了<code>ContextLoaderListener</code> 监听器之前导致配置没有生效</strong><h2 id="如果SpringMVC按照上述配置无法成功解决办法"><a href="#如果SpringMVC按照上述配置无法成功解决办法" class="headerlink" title="如果SpringMVC按照上述配置无法成功解决办法"></a>如果SpringMVC按照上述配置无法成功解决办法</h2><h3 id="1-引入logback与spring整合的依赖设置后可以自定义logback-xml的文件名-路径"><a href="#1-引入logback与spring整合的依赖设置后可以自定义logback-xml的文件名-路径" class="headerlink" title="1.引入logback与spring整合的依赖设置后可以自定义logback.xml的文件名/路径"></a>1.引入logback与spring整合的依赖设置后可以自定义logback.xml的文件名/路径</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.logback-extensions<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>logback-ext-spring<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>0.1.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="2-将logback-xml文件的名字修改，比如叫logback-aaa-xml"><a href="#2-将logback-xml文件的名字修改，比如叫logback-aaa-xml" class="headerlink" title="2.将logback.xml文件的名字修改，比如叫logback-aaa.xml"></a>2.将logback.xml文件的名字修改，比如叫logback-aaa.xml</h3><h3 id="3-在web-xml中配置logback配置文件初始化（注：要写在spring配置的上边）"><a href="#3-在web-xml中配置logback配置文件初始化（注：要写在spring配置的上边）" class="headerlink" title="3.在web.xml中配置logback配置文件初始化（注：要写在spring配置的上边）"></a>3.在web.xml中配置logback配置文件初始化（注：要写在spring配置的上边）</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">context-param</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">param-name</span>&gt;</span>logbackConfigLocation<span class="tag">&lt;/<span class="name">param-name</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">param-value</span>&gt;</span>classpath:logback-aaa.xml<span class="tag">&lt;/<span class="name">param-value</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">context-param</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="4-将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器"><a href="#4-将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器" class="headerlink" title="4.将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器"></a>4.将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 项目开发/生产环境监听器</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> 段誉</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@create</span> 2019-02-21 10:28</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ErpContextLoaderListener</span> <span class="keyword">extends</span> <span class="title">LogbackConfigListener</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Override</span></span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">contextInitialized</span><span class="params">(ServletContextEvent event)</span> </span>&#123;</span><br><span class="line">    String attribute = event.getServletContext().getInitParameter(<span class="string">"spring.profiles.default"</span>);</span><br><span class="line">    System.setProperty(<span class="string">"DEV_MODEL"</span>, attribute);</span><br><span class="line">    <span class="keyword">super</span>.contextInitialized(event);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<div id="gitalk-container"></div>
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"><script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>

		<script>
		var gitalkConfig = {"clientID":"28a065e3b5afee156f4f","clientSecret":"e18104d6f3219526491fc42c892ff6a26b8f3e74","repo":"blog_comment","owner":"FENG1000","admin":["FENG1000"],"distractionFreeMode":false};
	    gitalkConfig.id = md5(location.pathname);
		var gitalk = new Gitalk(gitalkConfig);
	    gitalk.render("gitalk-container");
	    </script>
    
  <blockquote>
      <p>
          作者: 只是学习学习<br>
          邮箱: fengzxia1000@163.com<br>
          原文地址: <a href="https://fengzxia.gitee.io/posts/5f5c7dc7.html" target="_blank" rel="noopener">https://fengzxia.gitee.io/posts/5f5c7dc7.html</a><br>
          版权声明: 商业转载请联系作者获得授权，非商业转载请注明出处。
      </p>
  </blockquote>

  <script>
      function setClipboardText(event){
          // clipboardData 对象是为通过编辑菜单、快捷菜单和快捷键执行的编辑操作所保留的，也就是你复制或者剪切内容
          let clipboardData = event.clipboardData || window.clipboardData;
          // 如果未复制或者未剪切，则return出去
          if (!clipboardData) { return; }
          event.preventDefault();
          // Selection 对象，表示用户选择的文本范围或光标的当前位置。
          //     声明一个变量接收 -- 用户输入的剪切或者复制的文本转化为字符串
          let text = window.getSelection().toString();

          if (text) {
            // 如果文本存在则先取消文本默认事件
            event.preventDefault();
            // 通过调用常clipboardData对象的 setData(format, data) 方法；来设置相关文本
            // format: 一个DOMString 表示要添加到 drag object的拖动数据的类型。
            // data: 一个 DOMString表示要添加到 drag object的数据。
            var copyright = '\n\n'
                            + '\n著作权归作者所有。'
                            + '\n商业转载请联系作者获得授权，非商业转载请注明出处。'
                            + '\n作者: 只是学习学习'
                            + '\n邮箱: fengzxia1000@163.com'
                            + '\n原文地址: https://fengzxia.gitee.io/posts/5f5c7dc7.html'

            clipboardData.setData('text/plain', text + copyright);

          }
      };
      var contents = document.getElementsByClassName("content");
      // 监听文章内容的copy事件
      contents[0].addEventListener('copy',function(e){
          setClipboardText(e);
      });
  </script>

  </div>
</article>




        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot项目"><span class="toc-number">1.</span> <span class="toc-text">SpringBoot项目</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-区分线上线下环境配置"><span class="toc-number">1.1.</span> <span class="toc-text">1.区分线上线下环境配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-在logback中通过如下方式进行区分环境"><span class="toc-number">1.2.</span> <span class="toc-text">2.在logback中通过如下方式进行区分环境</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringMVC项目"><span class="toc-number">2.</span> <span class="toc-text">SpringMVC项目</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-区分线上线下环境配置-1"><span class="toc-number">2.1.</span> <span class="toc-text">1.区分线上线下环境配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-在pom文件中引入maven-war-plugin插件，这样作是为了在编译时，web-xml文件能识别-profileActive"><span class="toc-number">2.2.</span> <span class="toc-text">2.在pom文件中引入maven-war-plugin插件，这样作是为了在编译时，web.xml文件能识别${profileActive}</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-在web-xml文件中修改spring-profiles-default配置，没有则添加"><span class="toc-number">2.3.</span> <span class="toc-text">3.在web.xml文件中修改spring.profiles.default配置，没有则添加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-创建一个监听器，继承ContextLoaderListener"><span class="toc-number">2.4.</span> <span class="toc-text">4.创建一个监听器，继承ContextLoaderListener</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-引入logback使用if判断需要的依赖"><span class="toc-number">2.5.</span> <span class="toc-text">5.引入logback使用if判断需要的依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-在logback中使用if判断区分环境"><span class="toc-number">2.6.</span> <span class="toc-text">6.在logback中使用if判断区分环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置后没有生效的原因"><span class="toc-number">2.7.</span> <span class="toc-text">配置后没有生效的原因</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#如果SpringMVC按照上述配置无法成功解决办法"><span class="toc-number">3.</span> <span class="toc-text">如果SpringMVC按照上述配置无法成功解决办法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-引入logback与spring整合的依赖设置后可以自定义logback-xml的文件名-路径"><span class="toc-number">3.1.</span> <span class="toc-text">1.引入logback与spring整合的依赖设置后可以自定义logback.xml的文件名&#x2F;路径</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-将logback-xml文件的名字修改，比如叫logback-aaa-xml"><span class="toc-number">3.2.</span> <span class="toc-text">2.将logback.xml文件的名字修改，比如叫logback-aaa.xml</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-在web-xml中配置logback配置文件初始化（注：要写在spring配置的上边）"><span class="toc-number">3.3.</span> <span class="toc-text">3.在web.xml中配置logback配置文件初始化（注：要写在spring配置的上边）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器"><span class="toc-number">3.4.</span> <span class="toc-text">4.将之前配置的监听器改成继承LogbackConfigListener，配置logback文件初始化的监听器</span></a></li></ol></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://fengzxia.gitee.io/posts/5f5c7dc7.html" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&text=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&is_video=false&description=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=Spring项目logback配置多环境日志输出&body=Check out this article: https://fengzxia.gitee.io/posts/5f5c7dc7.html"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&title=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://fengzxia.gitee.io/posts/5f5c7dc7.html&name=Spring项目logback配置多环境日志输出&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=https://fengzxia.gitee.io/posts/5f5c7dc7.html&t=Spring项目logback配置多环境日志输出" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2019-2020
    只是学习学习
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"复制到粘贴板!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "复制成功!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?54382acbd8c4bc66535bce135e0ac166";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


</body>
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https'){
   bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else{
  bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</html>
